package com.zryc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zryc.mapper.UserMapper;
import com.zryc.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zryc.shop.entity.User;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xujiajun
 * @since 2022-10-29
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public User login(String username, String password) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("username",username);
        User user=getOne(wrapper);//用户名唯一,保证我们最多就能查到一条记录
        if (user!=null){//用户名市存在的
            if (BCrypt.checkpw(password,user.getPassword())){//校验密码是否正确
                return user;
            }
        }
        return null;
    }
}
